package service;

import dao.FinancingProductDao;
import entity.FinancingProduct;

import java.sql.SQLException;
import java.util.List;

public class FinancingProductService {

    private FinancingProductDao dao = new FinancingProductDao();

    public List<FinancingProduct> getAllProducts() throws SQLException {
        return dao.getAllProducts();
    }

    public List<FinancingProduct> searchByCriteria(String keyword, int risk) throws SQLException {
        return dao.searchByCriteria(keyword, risk);
    }

    public boolean addProduct(FinancingProduct product) throws SQLException {
        return dao.addProduct(product);
    }

    public boolean modifyProduct(FinancingProduct product) throws SQLException {
        return dao.modifyProduct(product);
    }

    public boolean deleteProduct(String id) throws SQLException {
        return dao.deleteProduct(id);
    }

    public FinancingProduct getProductById(String id) throws SQLException {
        List<FinancingProduct> products = dao.searchByCriteria(id, -1);
        return products.isEmpty() ? null : products.get(0);
    }
}
